Bug/fix inappropriate symbol and ! for factorial#255
Conversation
Added ∞ as an alias for oo so students can use the Unicode infinity symbol as input. Fixed comparison of infinite expressions by using direct sympy comparison instead of subtraction, since oo - oo yields nan rather than 0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rning for unsupported triple factorial notation
…d-!-for-factorial
|
Database testing can be found here: https://github.com/lambda-feedback/compareExpressions/actions/runs/25786405204/job/75740792212 7 errors out of 1000
|
peterbjohnson
left a comment
There was a problem hiding this comment.
All ok with me and I've added an inline comment from Phil on the comparison of infinities. We'll do it and see how it goes.
| def do_comparison_infinite(comparison_symbol, lhs_expr, rhs_expr): | ||
| # When either side is infinite, subtracting (e.g. oo - oo) yields nan, making | ||
| # the subtraction-based do_comparison unreliable. Compare the sides directly instead. | ||
| direct_comparisons = { |
There was a problem hiding this comment.
Comment from Phil Ramsden after I asked him about this:
"I'm not speaking here as a mathematician exactly, but as someone who's written this kind of code for METRIC back in the day! The rationale for comparing the difference to zero is that zero is unambiguously "simpler" than almost any expression equivalent to it, and is therefore a likely end point for any chain of simplification. By contrast, it's possible to imagine (and not all that hard to concoct) examples of expressions that are algebraically equivalent but don't simplify to the same thing.
However, there are, potentially, several pitfalls with "compare difference to zero". Infinity is one of them, as there's no well-defined difference operation for infinities. A slightly different class of issue arises where the standard difference operation on equivalent objects exists all right, but yields something other than zero, such as the zero vector or (perhaps, depending on how difference is set up) the empty set. So "compare difference to zero" is not a panacea, and should only really be used when comparing symbolic expressions that represent scalars of some sort."
Requires #247 to be merged first before merging this PR.
Problem
Two bugs affecting infinity and factorial handling in symbolic expression comparison:
Fix
Other changes